<?php

namespace App\Models\Application;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class CollistData
 * @package App\Models\Application
 * @version July 19, 2018, 3:53 pm CST
 *
 * @property \App\Models\Application\Collist collist
 * @property integer collist_id
 * @property integer data_type
 * @property integer data_id
 * @property string icon
 * @property string onclick
 * @property string data
 */
class CollistData extends Model
{
    use SoftDeletes;

    public $table = 'collist_datas';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'collist_id',
        'data_type',
        'data_id',
        'icon',
        'data',
        'listorder',
        // 模板选择范围
        'range',
        // 模板ID
        'tpl_id',
        // 背景图
        'bg',
        // onclick信息描述
        'message',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'collist_id' => 'integer',
        'data_type'  => 'integer',
        'data_id'    => 'integer',
        'icon'       => 'string',
        'data'       => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'data_type' => 'required',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function collist()
    {
        return $this->hasOne(\App\Models\Entity\Column\Collist::class, 'id', 'collist_id');
    }
    /**
     * 关联栏目类型
     * @return [type] [description]
     */
    public function columnType()
    {
        return $this->hasOne(\App\Models\Entity\Column\ColumnType::class, 'id', 'data_type');
    }

    /**
     * 获得此媒资的所有标签。
     */
    public function tags()
    {
        return $this->morphToMany(\App\Models\Entity\Tag\tag::class, 'tag_content');
    }
}
